
import sublime, sublime_plugin
import os, subprocess

# 打开配置文件
def openSettingFile(view, flag):

	window = view.window()

	root = os.path.join(sublime.packages_path(), "wlgame-plugin")

	filePath = None

	if flag == 0:
		filePath = os.path.join(root, "wlgame-plugin.sublime-settings")

	if filePath:
		window.open_file(filePath)
	else:
		sublime.message_dialog("配置文件不存在")

class wlgame_sync_game_codeCommand(sublime_plugin.TextCommand):

	def run(self, edit):
		
		view = self.view

		settings = sublime.load_settings("wlgame-plugin.sublime-settings")
		mjcgPath = settings.get("mjcg_client_path");
		print(mjcgPath)

		if mjcgPath == None or len(mjcgPath) == 0:
			sublime.message_dialog("子游戏工程(mjcg-client)路径未配置")
			openSettingFile(view, 0)
			return 

		gameZipPath = os.path.join(mjcgPath, "gamezip")
		os.chdir(gameZipPath)

		cmd = "python CopyNotUpdateRes.py"
		subprocess.Popen(cmd)

		view.show_popup("<h3>正在执行代码同步，请稍候...</h3>")

class wlgame_build_gamezipCommand(sublime_plugin.TextCommand):

	def run(self, edit):

		view = self.view

		settings = sublime.load_settings("wlgame-plugin.sublime-settings")
		mjcgPath = settings.get("mjcg_client_path");

		if mjcgPath == None or len(mjcgPath) == 0:
			sublime.message_dialog("子游戏工程(mjcg-client)路径未配置")
			openSettingFile(view, 0)
			return 


		gameZipPath = os.path.join(mjcgPath, "gamezip")
		os.chdir(gameZipPath)

		cmd = "python CREATE_ZIP.py"
		subprocess.Popen(cmd)

		view.show_popup("<h3>正在生成子游戏热更包，请稍候...</h3>")

		
